load("//common:defs.bzl", "copy_file")
load("//dotnet:defs.bzl", "csharp_library", "devtools_version_targets", "generated_assembly_info", "generated_resource_utilities", "nuget_pack", "nuget_package")
load(
    "//dotnet:selenium-dotnet-version.bzl",
    "ASSEMBLY_COMPANY",
    "ASSEMBLY_COPYRIGHT",
    "ASSEMBLY_INFORMATIONAL_VERSION",
    "ASSEMBLY_PRODUCT",
    "ASSEMBLY_VERSION",
    "SE_VERSION",
)

exports_files([
    "WebDriver.csproj",
    "Properties/StringSyntaxAttribute.cs",
    "Properties/StringSyntaxConstants.cs",
])

generated_assembly_info(
    name = "assembly-info",
    company = ASSEMBLY_COMPANY,
    copyright = ASSEMBLY_COPYRIGHT,
    description = "Selenium WebDriver API .NET Bindings",
    informational_version = ASSEMBLY_INFORMATIONAL_VERSION,
    product = ASSEMBLY_PRODUCT,
    title = "Selenium WebDriver",
    version = ASSEMBLY_VERSION,
)

generated_resource_utilities(
    name = "resource-utilities",
    out = "ResourceUtilities.g.cs",
    resources = {
        "//javascript/atoms/fragments:find-elements.js": "FindElementsAtom",
        "//javascript/atoms/fragments:is-displayed.js": "IsDisplayedAtom",
        "//javascript/cdp-support:mutation-listener.js": "MutationListenerAtom",
        "//javascript/webdriver/atoms:get-attribute.js": "GetAttributeAtom",
        "//third_party/js/selenium:webdriver_json": "WebDriverPrefsJson",
    },
)

csharp_library(
    name = "webdriver-net462",
    srcs = [
        ":assembly-info",
        ":resource-utilities",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver",
    internals_visible_to = [
        "WebDriver.Common.Tests",
    ],
    langversion = "12.0",
    nullable = "enable",
    target_frameworks = [
        "net462",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
        nuget_package("Microsoft.Bcl.AsyncInterfaces"),
        nuget_package("System.Buffers"),
        nuget_package("System.Threading.Tasks.Extensions"),
        nuget_package("System.Memory"),
        nuget_package("System.Runtime.CompilerServices.Unsafe"),
        nuget_package("System.Text.Encodings.Web"),
        nuget_package("System.Text.Json"),
        nuget_package("System.ValueTuple"),
    ],
)

csharp_library(
    name = "webdriver-netstandard2.0",
    srcs = [
        ":assembly-info",
        ":resource-utilities",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver",
    internals_visible_to = [
        "WebDriver.Common.Tests",
    ],
    langversion = "12.0",
    nullable = "enable",
    resources = [],
    target_frameworks = [
        "netstandard2.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
        nuget_package("NETStandard.Library"),
        nuget_package("Microsoft.Bcl.AsyncInterfaces"),
        nuget_package("System.Buffers"),
        nuget_package("System.Threading.Tasks.Extensions"),
        nuget_package("System.Memory"),
        nuget_package("System.Runtime.CompilerServices.Unsafe"),
        nuget_package("System.Text.Encodings.Web"),
        nuget_package("System.Text.Json"),
    ],
)

csharp_library(
    name = "webdriver-net8.0",
    srcs = [
        ":assembly-info",
        ":resource-utilities",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver",
    defines = [
        "NET8_0_OR_GREATER",
    ],
    internals_visible_to = [
        "WebDriver.Common.Tests",
    ],
    langversion = "12.0",
    nullable = "enable",
    resources = [],
    target_frameworks = [
        "net8.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
    ],
)

csharp_library(
    name = "webdriver-net462-strongnamed",
    srcs = [
        ":assembly-info",
        ":resource-utilities",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver.StrongNamed",
    keyfile = "//dotnet:Selenium.snk",
    langversion = "12.0",
    nullable = "enable",
    target_frameworks = [
        "net462",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
        nuget_package("Microsoft.Bcl.AsyncInterfaces"),
        nuget_package("System.Buffers"),
        nuget_package("System.Threading.Tasks.Extensions"),
        nuget_package("System.Memory"),
        nuget_package("System.Runtime.CompilerServices.Unsafe"),
        nuget_package("System.Text.Encodings.Web"),
        nuget_package("System.Text.Json"),
        nuget_package("System.ValueTuple"),
    ],
)

csharp_library(
    name = "webdriver-netstandard2.0-strongnamed",
    srcs = [
        ":assembly-info",
        ":resource-utilities",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver.StrongNamed",
    keyfile = "//dotnet:Selenium.snk",
    langversion = "12.0",
    nullable = "enable",
    resources = [],
    target_frameworks = [
        "netstandard2.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
        nuget_package("NETStandard.Library"),
        nuget_package("Microsoft.Bcl.AsyncInterfaces"),
        nuget_package("System.Buffers"),
        nuget_package("System.Threading.Tasks.Extensions"),
        nuget_package("System.Memory"),
        nuget_package("System.Runtime.CompilerServices.Unsafe"),
        nuget_package("System.Text.Encodings.Web"),
        nuget_package("System.Text.Json"),
    ],
)

csharp_library(
    name = "webdriver-net8.0-strongnamed",
    srcs = [
        ":assembly-info",
        ":resource-utilities",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver.StrongNamed",
    defines = [
        "NET8_0_OR_GREATER",
    ],
    keyfile = "//dotnet:Selenium.snk",
    langversion = "12.0",
    nullable = "enable",
    resources = [],
    target_frameworks = [
        "net8.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
    ],
)

copy_file(
    name = "assets-nuget-readme",
    src = "//dotnet/src/webdriver/assets:nuget/README.md",
    out = "README.md",
)

copy_file(
    name = "assets-nuget-build-targets",
    src = "//dotnet/src/webdriver/assets:nuget/build/Selenium.WebDriver.targets",
    out = "Selenium.WebDriver.targets",
)

copy_file(
    name = "assets-nuget-buildtransitive-targets",
    src = "//dotnet/src/webdriver/assets:nuget/buildTransitive/Selenium.WebDriver.targets",
    out = "transitiveSelenium.WebDriver.targets",
)

copy_file(
    name = "manager-linux",
    src = "//common/manager:selenium-manager-linux",
    out = "manager/linux/selenium-manager",
    visibility = ["//dotnet/test/common:__pkg__"],
)

copy_file(
    name = "manager-macos",
    src = "//common/manager:selenium-manager-macos",
    out = "manager/macos/selenium-manager",
    visibility = ["//dotnet/test/common:__pkg__"],
)

copy_file(
    name = "manager-windows",
    src = "//common/manager:selenium-manager-windows",
    out = "manager/windows/selenium-manager.exe",
    visibility = ["//dotnet/test/common:__pkg__"],
)

nuget_pack(
    name = "webdriver-pack",
    files = {
        "//common/images:selenium_logo_small.png": "icon.png",
        "//common/manager:selenium-manager-linux": "manager/linux/selenium-manager",
        "//common/manager:selenium-manager-macos": "manager/macos/selenium-manager",
        "//common/manager:selenium-manager-windows": "manager/windows/selenium-manager.exe",
        ":assets-nuget-readme": "README.md",
        ":assets-nuget-build-targets": "build/Selenium.WebDriver.targets",
        ":assets-nuget-buildtransitive-targets": "buildTransitive/Selenium.WebDriver.targets",
    },
    id = "Selenium.WebDriver",
    libs = {
        ":webdriver-net462": "WebDriver",
        ":webdriver-net8.0": "WebDriver",
        ":webdriver-netstandard2.0": "WebDriver",
    },
    nuspec_template = "Selenium.WebDriver.nuspec",
    tags = [
        "block-network",
    ],
    version = SE_VERSION,
    visibility = [
        "//dotnet:__subpackages__",
    ],
)

nuget_pack(
    name = "webdriver-strongnamed-pack",
    files = {
        "//common/images:selenium_logo_small.png": "icon.png",
        "//common/manager:selenium-manager-linux": "manager/linux/selenium-manager",
        "//common/manager:selenium-manager-macos": "manager/macos/selenium-manager",
        "//common/manager:selenium-manager-windows": "manager/windows/selenium-manager.exe",
        ":assets-nuget-readme": "README.md",
        ":assets-nuget-build-targets": "build/Selenium.WebDriver.StrongNamed.targets",
        ":assets-nuget-buildtransitive-targets": "buildTransitive/Selenium.WebDriver.StrongNamed.targets",
    },
    id = "Selenium.WebDriver.StrongNamed",
    libs = {
        ":webdriver-net462-strongnamed": "WebDriver.StrongNamed",
        ":webdriver-net8.0-strongnamed": "WebDriver.StrongNamed",
        ":webdriver-netstandard2.0-strongnamed": "WebDriver.StrongNamed",
    },
    nuspec_template = "Selenium.WebDriver.StrongNamed.nuspec",
    property_group_vars = {
        "BaseImagePath": "images",
        "BaseSeleniumManagerPath": "manager",
    },
    tags = [
        "block-network",
    ],
    version = SE_VERSION,
    visibility = [
        "//dotnet:__subpackages__",
    ],
)
